var htmldomid = "";
var formStatus = true;
var commentStatus = true;
var siteHtml = {};

$(document).ready(function(){
    var windowheight = $(window).height();
    $(".edit-cotainer").css("height",windowheight-75);
    $(".htmldom-cotainer").css("height",windowheight-150);

    // 加载落地页自动加载元素组件
    firstLoadPage();

    $(document).on("click",'.edit-htmldom',function(){
        removeHtmldomActivity('action');
        var id =  $(this).attr("id");
        renderEdit(id);
    });

    $(document).on("click",'.site-button-top',function(){
        removeHtmldomActivity('action');
        var id =  $(this).attr("id");
        renderEdit(id);
    });

    $(document).on("click",'.site-button-bottom',function(){
        removeHtmldomActivity('action');
        var id =  $(this).attr("id");
        renderEdit(id);
    });

    $(document).on("click",'.site-button-right',function(){
        removeHtmldomActivity('action');
        var id =  $(this).attr("id");
        renderEdit(id);
    });

    $(document).on("click",'.site-button-drag',function(){
        removeHtmldomActivity('action');
        var id =  $(this).attr("id");
        renderEdit(id);
    });

    $("#domlistsleft li").click(function(){
        $(".domlists-right ul").hide();
        $("#domlistsleft li").removeClass("active");
        var type =  $(this).attr("type");
        $(this).addClass("active");
        $("#edit_left_"+type).show();
    });

    $("#redirect_type_list li").click(function(){
        $("#redirect_type_list li").removeClass("active");
        $(this).addClass("active");
        var redirect_type =  $(this).attr("data");
        siteHtml.redirect_type = redirect_type;
    });

    $("#right_header li").click(function(){
        $("#right_header li").removeClass("active");
        $(this).addClass("active");
        var header_type = $(this).attr("id");
        var activePlatfrom = $(".htmldom-activity").attr("platfrom");
        if (activePlatfrom == "wechat") {
            $("#edit_right_wechat_info").hide();
            $("#edit_right_wechat_style").hide();
            $("#edit_right_wechat_"+header_type).show();
        } else if (activePlatfrom == "form") {
            $("#edit_right_form_info").hide();
            $("#edit_right_form_style").hide();
            $("#edit_right_form_"+header_type).show();
        } else if (activePlatfrom == "text") {
            $("#edit_right_text_info").hide();
            $("#edit_right_text_style").hide();
            $("#edit_right_text_"+header_type).show();
        }
    });

    $("#button_method_lists li").click(function(){
        var methodn_value = $(this).attr("data");
        $("#button_method_lists li").removeClass("active");
        $(this).addClass("active");
        var site_id = $("#site_id").val();
        if (methodn_value == "showFrom") {
            // 新添加弹出表单
            if($("#showRegisterFrom").length <= 0){
                // 没有from则新添加
                $(".htmldom-cotainer").append('<div class="site-from-contain" id="showRegisterFrom"><div class="site-from-alert-shadow"></div><div class="site-from-alert-contain"><div class="site-from-one" style="color:#FD6666"><div class="top-notice" val="1"><span>购买倒计时:</span><font>30S</font></div><div class="site-from-one-lists"><input type="text" name="phone" id="phone10" placeholder="请输入手机号码" onchange="formDataChange(this);" autocomplete="off"></div><div class="site-from-one-code" val="1"><input type="text" name="code" id="code10" placeholder="请输入验证码" placeholder="请输入验证码" maxlength="4" onchange="formDataChange(this);" autocomplete="off"><span onclick="sendSmsCode(this);" id="sendcode10">发送验证码</span></div><div class="site-from-one-radio"><input type="checkbox" name="privacy" id="privacy10" onchange="formDataChange(this);"><label for="privacy10">已阅读并同意<a href="/site_privacy/'+site_id+'">《隐私协议》</a></label></div><div class="site-from-one-button" onclick="registerSubmit(this);" id="showFrmoButtonText">立即咨询</div></div><div class="site-from-close"><i class="iconfont icon-news-failure" onclick="hideFrom();"></i></div></div></div>');
            }
        }
        buttonTypeRender(methodn_value);
    });

    $("#button_animation_lists li").click(function(){
        var animation_value = $(this).attr("data");
        $("#button_animation_lists li").removeClass("active");
        $(this).addClass("active");
        var atag = $("#"+htmldomid).children("a");
        $("#button_"+animation_value).show();
        if (atag.length >= 1) {
            var childrenClass = $("#"+htmldomid+" a").attr("class");
        } else {
            var childrenClass = $("#"+htmldomid+" div").attr("class");
        }
        if (childrenClass.indexOf("circle-small") != -1) {
            var btnClasses = "site-button-default-circle-small";
        } else {
            var btnClasses = "site-button-default";
        }
        if (animation_value == "fullbeat") {
            btnClasses += " site-button-fullbeat";
        } else if(animation_value == "textbeat"){
            btnClasses += " site-button-textbeat";
        } else {
            btnClasses += "";
        }

        if (atag.length >= 1) {
            $("#"+htmldomid+" a").attr("class",btnClasses);
        } else {
            $("#"+htmldomid+" div").attr("class",btnClasses);
        }
    });

    $("#wechat_animation_lists li").click(function(){
        var animation_value = $(this).attr("data");
        $("#wechat_animation_lists li").removeClass("active");
        $(this).addClass("active");
        var childrenDom = $("#"+htmldomid+" div");
        if (childrenDom.hasClass("wechat_one")) {
            if (animation_value == "fullbeat") {
                $("#"+htmldomid+" div").attr("class","wechat_one animation-fullbeat");
            } else if (animation_value == "textbeat") {
                $("#"+htmldomid+" div").attr("class","wechat_one animation-textbeat");
            } else {
                $("#"+htmldomid+" div").attr("class","wechat_one");
            }
        } else if (childrenDom.hasClass("wechat_two")) {
            if (animation_value == "textbeat") {
                $("#"+htmldomid+" .wechat_two .right").attr("class","right animation-textbeat");
            } else {
                $("#"+htmldomid+" .wechat_two .right").attr("class","right");
                $("#"+htmldomid+" .wechat_two").attr("class","wechat_two");
            }
        } else if (childrenDom.hasClass("wechat_three")) {
            if (animation_value == "fullbeat") {
                $("#"+htmldomid+" .wechat_three .right").attr("class","right animation-fullbeat");
            } else {
                $("#"+htmldomid+" .wechat_three .right").attr("class","right");
                $("#"+htmldomid+" .wechat_three").attr("class","wechat_three");
            }
        } else {
            if (animation_value == "fullbeat") {
                $("#"+htmldomid+" div").attr("class","wechat_right animation-fullbeat");
            } else if (animation_value == "textbeat") {
                $("#"+htmldomid+" div").attr("class","wechat_right animation-textbeat");
            } else {
                $("#"+htmldomid+" div").attr("class","wechat_right");
            }
        }
    });

    $("#wechat_icon_lists li").click(function(){
        $("#wechat_icon_lists li").removeClass("active");
        $(this).addClass("active");
        var data =  $(this).attr("data");
        if (data == "default") {
            $("#"+htmldomid+" i").show();
        } else {
            $("#"+htmldomid+" i").hide();
        }
    });

    $("#unit_form_method_lists li").click(function(){
        $("#unit_form_method_lists li").removeClass("active");
        $(this).addClass("active");
        var data =  $(this).attr("data");
        $("#unit_form_method").val(data);
        $("#form_method_"+htmldomid).val(data);
        if (data == "mini") {
            $("#unit_form_method_wechat").show();
            $("#unit_form_method_alert").hide();
        } else {
            $("#unit_form_method_wechat").hide();
            $("#unit_form_method_alert").show();
        }
    });

    $("#wechat_border_lists li").click(function(){
        $("#wechat_border_lists li").removeClass("active");
        $(this).addClass("active");
        var data =  $(this).attr("data");
        if (data == "default") {
            $("#"+htmldomid+" div").css("border-radius",".1rem");
        } else {
            $("#"+htmldomid+" div").css("border-radius","1.5rem");
        }
    });

    $("#wechat_size_lists li").click(function(){
        $("#wechat_size_lists li").removeClass("active");
        $(this).addClass("active");
        var data =  $(this).attr("data");
        if (data == "default") {
            $("#"+htmldomid+" div").css("font-size","18px");
            $("#"+htmldomid+" div i").css("font-size","24px");
        } else {
            $("#"+htmldomid+" div").css("font-size","20px");
            $("#"+htmldomid+" div i").css("font-size","24px");
        }
    });

    $("#header_size_lists li").click(function(){
        $("#header_size_lists li").removeClass("active");
        $(this).addClass("active");
        var data =  $(this).attr("data");
        if (data == "default") {
            $("#"+htmldomid+" .title").css({"font-size":"18px","line-height":"25px"});
        } else if (data == "big") {
            $("#"+htmldomid+" .title").css({"font-size":"20px","line-height":"30px"});
        } else {
            $("#"+htmldomid+" .title").css({"font-size":"25px","line-height":"35px"});
        }
    });

    $("#hkzs_redirect_row li").click(function(){
        $("#hkzs_redirect_row li").removeClass("active");
        $(this).addClass("active");
        var data =  $(this).attr("data");
        $("#hkzs_redirect").val(data);
    });

    $('.htmldom-cotainer').bind('dragover drop', function(event){
        messageToastr("error","目前不支持拖动图片!");
        event.preventDefault();
        return false;
    });
    $('.htmldom-cotainer').on('paste',function(){
        messageToastr("error","目前不支持粘贴!");
        return false;
    });

    $(".site-button-drag").draggable({
        axis:"y",
        containment:".htmldom-cotainer",
        cursor: "move",
        cursorAt:{top:10},
    });
});

$(window).resize( function  () {
    var windowheight = $(window).height();
    $(".edit-cotainer").css("height",windowheight-100);
});

function sendSmsCode() {
    console.log("function");
}

function formDataChange() {
    console.log("function");
}

function simpleSubmit() {
    console.log("function");
}

function editHtmlTitle() {
    $(".edit-right-from").hide();
    $("#edit_right_page_title").show();
    $("#right_header").hide();
    $(".edit-right-button").hide();
}

function removeHtmldomActivity(status) {
    $(".edit-htmldom").removeClass("htmldom-activity");
    $(".site-button-top").removeClass("htmldom-activity");
    $(".site-button-bottom").removeClass("htmldom-activity");
    $(".site-button-right").removeClass("htmldom-activity");
    $(".site-button-drag").removeClass("htmldom-activity");
}

function simpleSubmit() {
    return;
}

function showFrom() {
    return;
}

function editRightTitle(platfrom) {
    $("#right_header").show();
    $(".edit-right-button").show();
    if (platfrom == "img") {
        $("#right_header li").removeClass("active");
        $("#right_header #info").show().addClass("active");
        $("#right_header #style").hide();
    } else if (platfrom == "form") {
        $("#right_header li").removeClass("active");
        $("#right_header #info").show().addClass("active");
        $("#right_header #style").hide();
    } else if (platfrom == "button") {
        $("#right_header li").removeClass("active");
        $("#right_header #info").addClass("active");
    } else if (platfrom == "wechat") {
        $("#right_header li").removeClass("active");
        $("#right_header #info").show().addClass("active");
        var platfrom_detial = $("#"+htmldomid).attr("platfrom_detial");
        if (platfrom_detial == "wechat_four" || platfrom_detial == "wechat_bottom_four") {
            $("#right_header #style").hide();
        } else {
            $("#right_header #style").show();
        }
    } else if (platfrom == "text") {
        $("#right_header li").removeClass("active");
        $("#right_header #info").show().addClass("active");
        var platfrom_detial = $("#"+htmldomid).attr("platfrom_detial");
        if (platfrom_detial == "rich") {
            $("#right_header #style").hide();
        } else {
            $("#right_header #style").show();
        }
    } else {
        $("#right_header li").removeClass("active");
        $("#right_header #info").show().addClass("active");
        $("#right_header #style").hide();
    }
}

function renderFrom(unitformSetting) {
    var id = htmldomid;
    var platfrom = $("#"+id).attr("platfrom");
    var platfrom_detial = $("#"+id).attr("platfrom_detial");
    var site_id = $("#site_id").val();
    if (Object.keys(unitformSetting).length <= 0) {
        formStatus = false;
        $("#"+htmldomid).html('<p class="page-form-empty">请创建表单后,在右侧选择对应表单。</p>');
        return;
    }
    formStatus = true;
    if (platfrom_detial == "form_phone") {
        var name = unitformSetting.name_must == 1 ? "<i>*</i>"+unitformSetting.name : unitformSetting.name;
        var phone = unitformSetting.phone_must == 1 ? "<i>*</i>"+unitformSetting.phone : unitformSetting.phone;
        var button_class = 'page-from-button animation-'+unitformSetting.button_animation;
        var title = (unitformSetting.title != "") ? '<div class="page-form-title" id="page_form_title" style="">'+unitformSetting.title+'</div>' : '';
        var form_method = $("#unit_form_method").val();
        var unit_form_method_text = $("#unit_form_method_text").val();
        $("#"+htmldomid).html('<div class="page-from"><div class="page-from-one" style="color:#FD6666">'+title+'<input type="hidden" id="form_id_'+id+'" value="'+unitformSetting.form_id+'"><input type="hidden" id="form_method_'+id+'" value="'+form_method+'"><input type="hidden" id="form_method_text_'+id+'" value="'+unit_form_method_text+'"><div class="page-from-lists" id="page_from_name_'+id+'"><label>'+name+'</label><input type="text" name="name" id="name_'+id+'" placeholder="'+unitformSetting.name_place+'" onchange="formDataChange(this);" autocomplete="off"></div><div class="page-from-lists" id="page_from_phone_'+id+'"><label>'+phone+'</label><input type="text" name="phone" id="phone_'+id+'" placeholder="'+unitformSetting.phone_place+'" onchange="formDataChange(this);" autocomplete="off"></div><div class="page-from-code-radio" id="page_from_privacy_'+id+'"><input type="checkbox" name="privacy" id="privacy_'+id+'" onchange="formDataChange(this);"><label for="privacy_'+id+'">已阅读并同意<a href="/site_privacy/'+site_id+'">《隐私协议》</a></label></div><div class="'+button_class+'" onclick="registerSubmit(this);" style="border-radius:'+unitformSetting.button_radius+'px;background-color:'+unitformSetting.button_background_color+';color:'+unitformSetting.button_color+';" id="register_'+id+'">'+unitformSetting.button_text+'</div></div></div>');
    } else {
        $("#"+htmldomid).html('<div class="page-from"><div class="page-from-one" style="color:#FD6666"><input type="hidden" id="form_id_'+id+'" value="'+unitformSetting.form_id+'"><div class="page-from-lists" id="page_from_name'+id+'"><label><i>*</i>您的姓名</label><input type="text" name="name" id="name'+id+'" placeholder="请输入姓名" onchange="formDataChange(this);" autocomplete="off"></div><div class="page-from-lists" id="page_from_phone'+id+'"><label><i>*</i>电话</label><input type="text" name="phone" id="phone'+id+'" placeholder="请输入手机号码" onchange="formDataChange(this);" autocomplete="off"></div><div class="page-from-code" id="page_from_code'+id+'"><input type="text" name="code" id="code'+id+'" placeholder="请输入验证码" maxlength="4" onchange="formDataChange(this);" autocomplete="off"><span onclick="sendSmsCode(this);" id="sendcode'+id+'">发送验证码</span></div><div class="page-from-code-radio" id="page_from_privacy'+id+'"><input type="checkbox" name="privacy" id="privacy'+id+'" onchange="formDataChange(this);"><label for="privacy'+id+'">已阅读并同意<a href="/site_privacy/'+site_id+'">《隐私协议》</a></label></div><div class="page-from-button" onclick="registerSubmit(this);" id="register'+id+'">立即领取</div></div></div>');
    }
}

function renderComment(comment) {
    var id = htmldomid;
    var platfrom = $("#"+id).attr("platfrom");
    var platfrom_detial = $("#"+id).attr("platfrom_detial");
    var site_id = $("#site_id").val();
    commentLists = JSON.parse(comment.message);
    if (Object.keys(commentLists).length <= 0) {
        commentStatus = false;
        $("#"+htmldomid).html('<p class="page-form-empty">请创建评论模版后,再在右侧选择模版。</p>');
        return;
    }
    commentStatus = true;
    $("#"+htmldomid +" .site-comment-lists").html('<div class="title" id="'+comment.id+'">'+comment.title+'</div>');
    $.each(commentLists,function(index,commentList){
        var replayHtml = '<ul>';
        $.each(commentList.replay,function(key,replay){
            replayHtml += '<li id="'+replay.id+'"><span>'+replay.nike+'</span><p>'+replay.message+'</p></li>';
        });
        replayHtml += '</ul>';
        $("#"+htmldomid +" .site-comment-lists").append('<div id="'+commentList.id+'" class="site-comment-items"><div class="site-comment-header"><img src="'+commentList.image+'"><div class="info"><p>'+commentList.nike+'</p><p>'+commentList.time+'</p></div></div><div class="message">'+commentList.message+'</div>'+replayHtml+'</div>');
    });
}

function renderEditAdd(platfrom,platfrom_detial) {
    var id = getRandomString(32);
    $(".htmldom-activity").removeClass("htmldom-activity");
    var site_id = $("#site_id").val();
    editRightTitle(platfrom);
    if (platfrom == "img") {
        $("#edit_right_img").show();
        $("#img_url").val("");
        $("#"+htmldomid).after('<div class="edit-htmldom" id="'+id+'" platfrom="img"><img draggable="false" src="https://p6-orange.byteorge.com/img/ad-tetris-site/f59c53720312352885ae5df5051d032f.png~q75.awebp" class="site-img-12"></div>');
    } else if (platfrom == "form") {
        $("#"+htmldomid).after('<div class="edit-htmldom" id="'+id+'"  platfrom="'+platfrom+'" platfrom_detial="'+platfrom_detial+'"></div>');
        usersUnitForm("add",platfrom_detial);
    } else if (platfrom == "button") {
        $("#edit_right_button").show();
        $("#button_url_input").val("");
        if(platfrom_detial == "button_top_small" || platfrom_detial == "button_top_full" || platfrom_detial == "button_top_img"){
            $(".site-button-top").remove();
            if(platfrom_detial == "button_top_small"){
                $(".htmldom-cotainer").prepend('<div id="'+id+'" platfrom="'+platfrom+'" platfrom_detial="'+platfrom_detial+'" class="site-button-top" onclick="simpleSubmit();"><div class="site-button-default-circle-small">顶部固定按钮</div></div>');
            } else if(platfrom_detial == "button_top_full") {
                $(".htmldom-cotainer").prepend('<div id="'+id+'" platfrom="'+platfrom+'" platfrom_detial="'+platfrom_detial+'" class="site-button-top" onclick="simpleSubmit();"><div class="site-button-default">顶部固定按钮</div></div>');
            } else {
                $(".htmldom-cotainer").prepend('<div id="'+id+'" platfrom="'+platfrom+'" platfrom_detial="'+platfrom_detial+'" class="site-button-top" onclick="simpleSubmit();"><img draggable="false" src="https://p6-orange.byteorge.com/img/ad-tetris-site/file/1551790136895/72aa31c3f84fe1b9827ec489f76d5762~q75.awebp" class="site-img-12"></div>');
            }
        } else if(platfrom_detial == "button_bottom_small" || platfrom_detial == "button_bottom_full" || platfrom_detial == "button_bottom_img"){
            $(".site-button-bottom").remove();
            if(platfrom_detial == "button_bottom_small"){
                $(".htmldom-cotainer").append('<div id="'+id+'" platfrom="'+platfrom+'" platfrom_detial="'+platfrom_detial+'" class="site-button-bottom" onclick="simpleSubmit();"><div class="site-button-default-circle-small">底部固定按钮</div></div>');
            } else if(platfrom_detial == "button_bottom_full") {
                $(".htmldom-cotainer").append('<div id="'+id+'" platfrom="'+platfrom+'" platfrom_detial="'+platfrom_detial+'" class="site-button-bottom" onclick="simpleSubmit();"><div class="site-button-default">底部固定按钮</div></div>');
            } else {
                $(".htmldom-cotainer").append('<div id="'+id+'" platfrom="'+platfrom+'" platfrom_detial="'+platfrom_detial+'" class="site-button-bottom" onclick="simpleSubmit();"><img draggable="false" src="https://p6-orange.byteorge.com/img/ad-tetris-site/file/1551790136895/72aa31c3f84fe1b9827ec489f76d5762~q75.awebp" class="site-img-12"></div>');
            }
        } else {
            var button_html = "";
            if(platfrom_detial == "button_small"){
                button_html = '<div class="site-button-default-circle-small">按钮</div>';
            } else if(platfrom_detial == "button_full") {
                button_html = '<div class="site-button-default">按钮</div>';
            } else {
                button_html = '<img draggable="false" src="https://p6-orange.byteorge.com/img/ad-tetris-site/file/1551790136895/72aa31c3f84fe1b9827ec489f76d5762~q75.awebp" class="site-img-12">';
            }
            $("#"+htmldomid).after('<div class="edit-htmldom" id="'+id+'" platfrom="'+platfrom+'" platfrom_detial="'+platfrom_detial+'">'+button_html+'</div>');
            $("#edit_right_button").show();
        }
    } else if (platfrom == "wechat") {
        $("#edit_right_wechat").show();
        if(platfrom_detial == "wechat_top_one" || platfrom_detial == "wechat_top_two" || platfrom_detial == "wechat_top_three" || platfrom_detial == "wechat_top_img"){
            $(".site-button-top").remove();
            if(platfrom_detial == "wechat_top_one"){
                $(".htmldom-cotainer").prepend('<div id="'+id+'" platfrom="'+platfrom+'" platfrom_detial="'+platfrom_detial+'" class="site-button-top"><div class="wechat_one" onclick="simpleSubmit();"><i class="iconfont icon-weixin"></i><font>点击立即前往微信</font></div></div>');
            } else if(platfrom_detial == "wechat_top_two") {
                $(".htmldom-cotainer").prepend('<div id="'+id+'" platfrom="'+platfrom+'" platfrom_detial="'+platfrom_detial+'" class="site-button-top"><div class="wechat_two"><div class="left">点击右侧按钮,前往微信</div><div class="right" onclick="simpleSubmit();"><i class="iconfont icon-weixin"></i><font>添加微信</font></div></div></div>');
            } else if(platfrom_detial == "wechat_top_three") {
                $(".htmldom-cotainer").prepend('<div id="'+id+'" platfrom="'+platfrom+'" platfrom_detial="'+platfrom_detial+'" class="site-button-top"><div class="wechat_three"><div class="left">点击右侧按钮,关注公众号</div><div class="right" onclick="simpleSubmit();"><i class="iconfont icon-zengjia"></i><font>关注</font></div></div></div>');
            } else {
                $(".htmldom-cotainer").prepend('<div id="'+id+'" platfrom="'+platfrom+'" platfrom_detial="'+platfrom_detial+'" class="site-button-top" onclick="simpleSubmit();"><img draggable="false" src="https://p6-orange.byteorge.com/img/ad-tetris-site/file/1551790136895/72aa31c3f84fe1b9827ec489f76d5762~q75.awebp" class="site-img-12"></div>');
            }
        } else if(platfrom_detial == "wechat_bottom_one" || platfrom_detial == "wechat_bottom_two" || platfrom_detial == "wechat_bottom_three" || platfrom_detial == "wechat_bottom_four" || platfrom_detial == "wechat_bottom_img"){
            $(".site-button-bottom").remove();
            if(platfrom_detial == "wechat_bottom_one"){
                $(".htmldom-cotainer").append('<div id="'+id+'" platfrom="'+platfrom+'" platfrom_detial="'+platfrom_detial+'" class="site-button-bottom"><div class="wechat_one" onclick="simpleSubmit();"><i class="iconfont icon-weixin"></i><font>点击立即前往微信</font></div></div>');
            } else if(platfrom_detial == "wechat_bottom_two") {
                $(".htmldom-cotainer").append('<div id="'+id+'" platfrom="'+platfrom+'" platfrom_detial="'+platfrom_detial+'" class="site-button-bottom"><div class="wechat_two"><div class="left">点击右侧按钮,前往微信</div><div class="right" onclick="simpleSubmit();"><i class="iconfont icon-weixin"></i><font>添加微信</font></div></div></div>');
            } else if(platfrom_detial == "wechat_bottom_three") {
                $(".htmldom-cotainer").append('<div id="'+id+'" platfrom="'+platfrom+'" platfrom_detial="'+platfrom_detial+'" class="site-button-bottom"><div class="wechat_three"><div class="left">点击右侧按钮,关注公众号</div><div class="right" onclick="simpleSubmit();"><i class="iconfont icon-zengjia"></i><font>关注</font></div></div></div>');
            } else if(platfrom_detial == "wechat_bottom_four") {
                $(".htmldom-cotainer").append('<div id="'+id+'" platfrom="'+platfrom+'" platfrom_detial="'+platfrom_detial+'" class="site-button-bottom"><div class="wechat_four"><div class="wechat_title"><font>微信号:</font><p class="duoyue_wechat">Wechat</p></div><p class="wechat_describe">长按复制微信号，去微信搜索添加</p></div></div>');
            } else {
                $(".htmldom-cotainer").append('<div id="'+id+'" platfrom="'+platfrom+'" platfrom_detial="'+platfrom_detial+'" class="site-button-bottom" onclick="simpleSubmit();"><img draggable="false" src="https://p6-orange.byteorge.com/img/ad-tetris-site/file/1551790136895/72aa31c3f84fe1b9827ec489f76d5762~q75.awebp" class="site-img-12"></div>');
            }
        } else if(platfrom_detial == "wechat_one" || platfrom_detial == "wechat_two" || platfrom_detial == "wechat_three" || platfrom_detial == "wechat_four" || platfrom_detial == "wechat_five" || platfrom_detial == "wechat_img"){
            var button_html = "";
            if(platfrom_detial == "wechat_one"){
                button_html = '<div class="wechat_one" onclick="simpleSubmit();"><i class="iconfont icon-weixin"></i><font>点击立即前往微信</font></div>';
            } else if(platfrom_detial == "wechat_two") {
                button_html = '<div class="wechat_two"><div class="left">点击右侧按钮,前往微信</div><div class="right" onclick="simpleSubmit();"><i class="iconfont icon-weixin"></i><font>添加微信</font></div></div>';
            } else if(platfrom_detial == "wechat_three") {
                button_html = '<div class="wechat_three"><div class="left">点击右侧按钮,关注公众号</div><div class="right" onclick="simpleSubmit();"><i class="iconfont icon-zengjia"></i><font>关注</font></div></div>';
            } else if(platfrom_detial == "wechat_four") {
                button_html = '<div class="wechat_four"><div class="wechat_title"><font>微信号:</font><p class="duoyue_wechat">Wechat</p></div><p class="wechat_describe">长按复制微信号，去微信搜索添加</p></div>';
            // } else if(platfrom_detial == "wechat_five") {
            //     button_html = '<div class="wechat_five"><p>我是本地正规挂牌导游，您可以加我的微信进行详细咨询<font id="duoyue_wechat"微信号：Wechat</font>我在这个知名度颇高的城市从事旅游业6年多，擅长导游接待和旅游策划。</p></div>';
            } else {
                button_html = '<img draggable="false" src="https://p6-orange.byteorge.com/img/ad-tetris-site/file/1551790136895/72aa31c3f84fe1b9827ec489f76d5762~q75.awebp" class="site-img-12" onclick="simpleSubmit();">';
            }
            $("#"+htmldomid).after('<div class="edit-htmldom" id="'+id+'" platfrom="'+platfrom+'" platfrom_detial="'+platfrom_detial+'">'+button_html+'</div>');
            $("#edit_right_wechat").show();
        } else if (platfrom_detial == "wechat_drag_one" || platfrom_detial == "wechat_drag_two" || platfrom_detial == "wechat_drag_three" || platfrom_detial == "wechat_drag_img") {
            if(platfrom_detial == "wechat_drag_one"){
                $(".htmldom-cotainer").append('<div id="'+id+'" platfrom="'+platfrom+'" platfrom_detial="'+platfrom_detial+'" class="site-button-drag"><div class="wechat_one" onclick="simpleSubmit();"><i class="iconfont icon-weixin"></i><font>点击立即前往微信</font></div></div>');
            } else if(platfrom_detial == "wechat_drag_two") {
                $(".htmldom-cotainer").append('<div id="'+id+'" platfrom="'+platfrom+'" platfrom_detial="'+platfrom_detial+'" class="site-button-drag"><div class="wechat_two"><div class="left">点击右侧按钮,前往微信</div><div class="right" onclick="simpleSubmit();"><i class="iconfont icon-weixin"></i><font>添加微信</font></div></div></div>');
             } else if(platfrom_detial == "wechat_drag_three") {
                $(".htmldom-cotainer").append('<div id="'+id+'" platfrom="'+platfrom+'" platfrom_detial="'+platfrom_detial+'" class="site-button-drag"><div class="wechat_three"><div class="left">点击右侧按钮,关注公众号</div><div class="right" onclick="simpleSubmit();"><i class="iconfont icon-zengjia"></i><font>关注</font></div></div></div>');
            } else {
                $(".htmldom-cotainer").append('<div id="'+id+'" platfrom="'+platfrom+'" platfrom_detial="'+platfrom_detial+'" class="site-button-drag" onclick="simpleSubmit();"><img draggable="false" src="https://p6-orange.byteorge.com/img/ad-tetris-site/file/1551790136895/72aa31c3f84fe1b9827ec489f76d5762~q75.awebp" class="site-img-12"></div>');
            }
            addSiteDraggable(id);
        } else {
            $(".site-button-right").remove();
            $(".htmldom-cotainer").append('<div id="'+id+'" platfrom="'+platfrom+'" platfrom_detial="'+platfrom_detial+'" class="site-button-right"><div class="wechat_right" onclick="simpleSubmit();"><i class="iconfont icon-weixin"></i></div></div>');
            addSiteDraggable(id);
        }
    } else {
        $("#edit_right_text").show();
        var nowTime = moment().format("YYYY-MM-DD HH:mm")
        if(platfrom_detial == "gzh_head"){
            $("#"+htmldomid).after('<div class="edit-htmldom" id="'+id+'" platfrom="'+platfrom+'" platfrom_detial="'+platfrom_detial+'"><div class="site-text-header"><div class="gzh"><div class="title">请输入文章标题</div><div class="info"><p class="editor">作者</p><a class="come" target="_blank" href="">文章来源</a><p class="time">'+nowTime+'</p></div></div></div></div>');
        } else if(platfrom_detial == "jrtt_head") {
            $("#"+htmldomid).after('<div class="edit-htmldom" id="'+id+'" platfrom="'+platfrom+'" platfrom_detial="'+platfrom_detial+'"><div class="site-text-header"><div class="title">请输入文章标题</div><div class="toutiao"><img src="https://res.doyea.cn/uploads/20230427/9051106.png"><div class="info"><p class="editor">作者</p><p class="time">'+nowTime+'</p></div></div></div></div>');
        } else if(platfrom_detial == "comment") {
            $("#"+htmldomid).after('<div class="edit-htmldom" id="'+id+'" platfrom="'+platfrom+'" platfrom_detial="'+platfrom_detial+'"><div class="site-comment-lists"></div>');
            usersSiteComment("add");
        } else {
            $("#"+htmldomid).after('<div class="edit-htmldom" id="'+id+'" platfrom="'+platfrom+'" platfrom_detial="'+platfrom_detial+'"><div class="site-text-cotainer"><p style="text-align: center;">文本信息</p></div></div>');
        }
    }
    htmldomid = id;
    // $("#"+id).addClass("htmldom-activity");
    renderEdit(id,platfrom);
}

function buttonTypeRender(buttontype) {
    $("#button_url").hide();
    $("#button_simpleSubmit").hide();
    $("#button_showFrom").hide();
    $("#button_"+buttontype).show();
    if (buttontype == "simpleSubmit") {
        $("#"+htmldomid).attr("onclick","simpleSubmit();");
        var atag = $("#"+htmldomid).children("a");
        if (atag.length >= 1) {
            var childrenClass = $("#"+htmldomid+" a").attr("class") || "";
            var childrenStyle = $("#"+htmldomid+" a").attr("style") || "";
            var childrentext = $("#"+htmldomid+" a").text() || "";
            // 判断是否有图片
            var imgexist = $("#"+htmldomid+" img").length;
            if (imgexist >= 1) {
                var imgsrc = $("#"+htmldomid+" img").attr("src");
                $("#"+htmldomid).html('<img draggable="false" src="'+imgsrc+'" class="site-img-12">');
            } else {
                $("#"+htmldomid).html('<div class="'+childrenClass+'" style="'+childrenStyle+'">'+childrentext+'</div>');
            }
        }
    } else if(buttontype == "showFrom"){
        var showFromType = $("#"+htmldomid).attr("onclick");
        if (showFromType == "showFrom(false);") {
            showFormCountDownShow(false);
        } else {
            showFormCountDownShow(true);
        }
        // 获取当前设置的弹出表单按钮
        var showFrmoButtonText = $("#showFrmoButtonText").text();
        $("#showFrmoButton").val(showFrmoButtonText);
        var showFrmoSendCode = $(".site-from-one-code").attr("val");
        $("#showFrmoSendCode").val(showFrmoSendCode);
        var showFrmoNotice = $(".top-notice span").text().replace(":", "");
        $("#showFrmoNotice").val(showFrmoNotice);
        var showFrmoTime = $(".top-notice font").text().replace("S", "");
        $("#showFrmoTime").val(showFrmoTime);

        var atag = $("#"+htmldomid).children("a");
        if (atag.length >= 1) {
            var childrenClass = $("#"+htmldomid+" a").attr("class") || "";
            var childrenStyle = $("#"+htmldomid+" a").attr("style") || "";
            var childrentext = $("#"+htmldomid+" a").text() || "";
            // 判断是否有图片
            var imgexist = $("#"+htmldomid+" img").length;
            if (imgexist >= 1) {
                var imgsrc = $("#"+htmldomid+" img").attr("src");
                $("#"+htmldomid).html('<img draggable="false" src="'+imgsrc+'" class="site-img-12">');
            } else {
                $("#"+htmldomid).html('<div class="'+childrenClass+'" style="'+childrenStyle+'">'+childrentext+'</div>');
            }
        }
    } else {
        $("#"+htmldomid).removeAttr("onclick");
        var buttonurl = $("#button_url_input").val();
        var atag = $("#"+htmldomid).children("a");
        if (atag.length <= 0) {
            var childrenClass = $("#"+htmldomid+" div").attr("class") || "";
            var childrenStyle = $("#"+htmldomid+" div").attr("style") || "";
            var childrentext = $("#"+htmldomid+" div").text() || "";
            // 判断是否有图片
            var imgexist = $("#"+htmldomid+" img").length;
            if (imgexist >= 1) {
                var imgsrc = $("#"+htmldomid+" img").attr("src");
                $("#"+htmldomid).html('<a href="'+buttonurl+'" target="_blank" class="'+childrenClass+'" style="'+childrenStyle+'"><img draggable="false" src="'+imgsrc+'" class="site-img-12"></a>');
            } else {
                 var buttontext = $("#"+htmldomid).text();
                $("#"+htmldomid).html('<a href="'+buttonurl+'" target="_blank" class="'+childrenClass+'" style="'+childrenStyle+'">'+buttontext+'</a>');
            }
        }
    }
}

function jsUploadCallBack(id,imageurl,imageName,updata) {
    $("#"+htmldomid+" img").attr("src",imageurl);
}

function hkzsLinksAdd() {
    window.open("/admin/hkzs/list_link");
}

function titleChange() {
    var title = $("#title").val();
    siteHtml.title = title;
    $("#site_html_title").text(title);
}

function imgUrlChange(object) {
    var id = object.id;
    var url = $("#"+id).val();
    if (url.indexOf("://") < 0) {
        messageToastr("error","链接错误,请输入正确的http链接和urlscheme!");
        return;
    }
    if (id == "button_url_input") {
        var atag = $("#"+htmldomid).children("a");
        if (atag.length >= 1) {
            var childrenClass = $("#"+htmldomid+" a").attr("class");
            var childrenStyle = $("#"+htmldomid+" a").attr("style");
            var childrentext = $("#"+htmldomid+" a").text();
        } else {
            var childrenClass = $("#"+htmldomid+" div").attr("class");
            var childrenStyle = $("#"+htmldomid+" div").attr("style");
            var childrentext = $("#"+htmldomid+" div").text();
        }
        $("#"+htmldomid).html('<a href="'+url+'" target="_blank" class="'+childrenClass+'" style="'+childrenStyle+'">'+childrentext+'</a>');
    } else {
        var imgsrc = $("#"+htmldomid+" img").attr("src");
        $("#"+htmldomid).html('<a href="'+url+'" target="_blank"><img draggable="false" src="'+imgsrc+'" class="site-img-12"></a>');
    }
}

function colorChange(object) {
    var id = object.id;
    var color = $("#"+id).val();
    if (id == "button_background_color") {
        var atag = $("#"+htmldomid).children("a");
        if (atag.length >= 1) {
            $("#"+htmldomid+" a").css("background-color",color);
        }
        var divtag = $("#"+htmldomid).children("div");
        if (divtag.length >= 1) {
            $("#"+htmldomid+" div").css("background-color",color);
        }
    } else if (id == "button_color") {
        var atag = $("#"+htmldomid).children("a");
        if (atag.length >= 1) {
            $("#"+htmldomid+" a").css("color",color);
        }
        var divtag = $("#"+htmldomid).children("div");
        if (divtag.length >= 1) {
            $("#"+htmldomid+" div").css("color",color);
        }
    } else if (id == "wechat_background_color") {
        var divtag = $("#"+htmldomid).children("div");
        if (divtag.hasClass("wechat_one")) {
            $("#"+htmldomid+" div").css("background-color",color);
        } else if (divtag.hasClass("wechat_two")) {
            $("#"+htmldomid+" .right").css("background-color",color);
        } else if (divtag.hasClass("wechat_three")) {
            $("#"+htmldomid+" .right").css("background-color",color);
        } else {
            $("#"+htmldomid+" div").css("background-color",color);
        }
    } else if (id == "wechat_color") {
        var divtag = $("#"+htmldomid).children("div");
        if (divtag.hasClass("wechat_one")) {
            $("#"+htmldomid+" div").css("color",color);
        } else if (divtag.hasClass("wechat_two")) {
            $("#"+htmldomid+" .right").css("color",color);
        } else if (divtag.hasClass("wechat_three")) {
            $("#"+htmldomid+" .right").css("color",color);
        } else {
            $("#"+htmldomid+" div").css("color",color);
        }
    } else if (id == "wechat_describe_color") {
        var divtag = $("#"+htmldomid).children("div");
        if (divtag.hasClass("wechat_two")) {
            $("#"+htmldomid+" .left").css("color",color);
        } else if (divtag.hasClass("wechat_three")) {
            $("#"+htmldomid+" .left").css("color",color);
        }
    } else if (id == "text_header_color") {
        $("#"+htmldomid+" .title").css("color",color);
    }
}

function wechatInputChange(object) {
    var id = object.id;
    var value = $("#"+id).val();

    var platfrom =  $("#"+htmldomid).attr("platfrom");
    var platfrom_detial =  $("#"+htmldomid).attr("platfrom_detial");
    if (id == "wechat_text") {
        if (platfrom_detial == "wechat_four" || platfrom_detial == "wechat_bottom_four") {
            $("#"+htmldomid+" .wechat_title font").text(value);
        } else {
            $("#"+htmldomid+" font").text(value);
        }
    } else if (id == "wechat_notice") {
        if (platfrom_detial == "wechat_four" || platfrom_detial == "wechat_bottom_four") {
            $("#"+htmldomid+" .wechat_describe").text(value);
        } else {
            $("#"+htmldomid+" .left").text(value);
        }
    } else if (id == "unit_form_method_text") {
        $("#form_method_text_"+htmldomid).val(value);
    } 
}

function textInputChange(object) {
    var id = object.id;
    var value = $("#"+id).val();

    var platfrom =  $("#"+htmldomid).attr("platfrom");
    var platfrom_detial =  $("#"+htmldomid).attr("platfrom_detial");
    if (id == "text_header_title") {
        $("#"+htmldomid+" .title").text(value);
    } else if (id == "text_header_editor") {
        $("#"+htmldomid+" .editor").text(value);
    } else if (id == "text_header_time") {
        $("#"+htmldomid+" .time").text(value);
    } else if (id == "text_header_come") {
        $("#"+htmldomid+" .come").text(value);
    } else if (id == "text_header_link") {
        if (value.indexOf("://") < 0 && value != "") {
            messageToastr("error","链接错误,请输入正确的http链接或者不填写!");
            return;
        }
        $("#"+htmldomid+" .come").attr("href",value);
    } 
}

function showFormCountDownShow(status){
    $("#show_form_lists li").removeClass("active");
    if (status) {
        $("#show_form_lists li").eq(1).addClass("active");
        $("#showFormCountDownShowRow").show();
        $(".top-notice").css("display","block");
        $("#"+htmldomid).attr("onclick","showFrom(true);");
    } else {
        $("#show_form_lists li").eq(0).addClass("active");
        $("#showFormCountDownShowRow").hide();
        $(".top-notice").css("display","none");
        $("#"+htmldomid).attr("onclick","showFrom(false);");
    }
}

function showFrmoSendCode(){
    var showFrmoSendCode = $("#showFrmoSendCode").val();
    if (showFrmoSendCode == 2) {
        $(".site-from-one-code").css("display","none").attr("val","2");
    } else {
        $(".site-from-one-code").css("display","block").attr("val","1");
    }
}

function showFrmoButton(){
    var showFrmoButton = $("#showFrmoButton").val();
    $(".site-from-one-button").text(showFrmoButton);
}

function showFrmoNotice() {
    var showFrmoNotice = $("#showFrmoNotice").val();
    $(".top-notice span").text(showFrmoNotice+":");
}

function showFrmoTime() {
    var showFrmoTime = $("#showFrmoTime").val();
    $(".top-notice font").text(showFrmoTime+"S");
}

// 文字字体设计
function tetxFontName() {
    var tetxFontName = $("#tetxFontName").val();
    if(tetxFontName == "1"){
        document.execCommand('fontName', false, '');
    } else {
        document.execCommand('fontName', false, 'Source Han Sans');
    }
}

// 文字对齐方式
function tetxAlignment(aligntype) {
    if(aligntype == "left"){
        document.execCommand('justifyLeft', 'false', null );
    } else if (aligntype == "center") {
        document.execCommand('justifyCenter', 'false', null );
    } else {
        document.execCommand('justifyRight', 'false', null );
    }
}

// 文字大小
function tetxFontSize(type) {
    var fontsize = parseInt($("#tetxFontSize").val());
    if (type == "inc") {
        fontsize += 1;
    } else {
        fontsize -= 1;
    }
    $("#tetxFontSize").val(fontsize);
    // let parent = document.execCommand();
    var selection = document.getSelection()
    // 设置最后光标对象
    lastEditRange = selection.getRangeAt(0);
    //选中区域的Element元素
    var elem = lastEditRange.commonAncestorContainer;
    if(elem.nodeType != 1){
        elem = elem.parentNode;
    }
    var lineheight = (fontsize*1.5).toFixed(0);
    $("#tetxLineHeight").val(lineheight);
    elem.style.fontSize = fontsize+"px";
    elem.style.height = lineheight+"px";
    elem.style.lineHeight = lineheight+"px";
}

// 行高
function tetxLineHeight(type) {
    var lineheight = parseInt($("#tetxLineHeight").val());
    if (type == "inc") {
        lineheight += 1;
    } else {
        lineheight -= 1;
    }
    $("#tetxLineHeight").val(lineheight);
    var selection = document.getSelection()
    // 设置最后光标对象
    lastEditRange = selection.getRangeAt(0);
    //选中区域的Element元素
    var elem = lastEditRange.commonAncestorContainer;
    if(elem.nodeType != 1){
        elem = elem.parentNode;
    }
    elem.style.height = lineheight+"px";
    elem.style.lineHeight = lineheight+"px";
}

function addSiteDraggable(id) {
    var start = {}
    $("#"+id).draggable({
        axis:"y",
        containment:".htmldom-cotainer",
        cursor: "move",
        cursorAt:{top:10},
        start:function(e,ui){
            start = ui.position;
        },
        drag:function(e,ui){
        },
        stop:function(e,ui){
            var site_button_top = $("#site-button-top");
            if (site_button_top.length>0) {

            }
            // if (ui.position.top > 100) {
            //     $("#"+id).css("top",start.position.top)
            // }
        }
    });
}

function getRandomString(len) {
    len = len || 32;
    var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
    var maxPos = $chars.length;
    var pwd = '';
    for (i = 0; i < len; i++) {
        pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
    }
    return pwd;
}

function registerSubmit() {
    console.log(1);
}

function privacy() {
    return;
}

function deleteHtmlDom() {
    var nexthtmldomid = $("#"+htmldomid).next().attr("id");
    var prevhtmldomid = $("#"+htmldomid).prev().attr("id");
    $("#"+htmldomid).remove();
    try {
        if (typeof(nexthtmldomid) == "undefined"){
            renderEdit(prevhtmldomid);
        } else {
            renderEdit(nexthtmldomid);
        }
    } catch(err){
    }
    var htmldomNumber = $(".edit-htmldom").length;

    if (htmldomNumber <= 0) {
        $(".htmldom-cotainer").html('<div class="edit-htmldom" id="YY76ERh23nRrHAzHc53w6NjfayXNc7T6" platfrom="img"><img draggable="false" src="https://doye.oss-cn-beijing.aliyuncs.com/static/images/site-default.jpg" class="site-img-12"></div>');
        renderEdit("YY76ERh23nRrHAzHc53w6NjfayXNc7T6");
    }
}

function publishPublic(type) {
    messageToastr("load","提交中,请稍等...",15);
    var html = $(".htmldom-cotainer").html();
    html = html.replaceAll("\r","");
    html = html.replaceAll("\n","");
    html = html.replaceAll("   ","");
    siteHtml.html = html.replaceAll("  ","");

    siteHtml.type = type;
    $.ajax({
        url: "/admin/wxkf/html_publish/"+siteHtml.kfid,
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        },
        type: "POST",
        data: siteHtml,
        success:function(data){
            colseMessageToastr();
            if (data.status == "success") {
                messageToastr("success",data.msg);
                if (type == "online" && siteHtml.publish_status == 1) {
                    siteHtml.publish_status = 2;
                    window.location.href = "/admin/hkzs/hkzs_detial/"+site_id;
                }
            } else {
                messageToastr("error",data.msg);
            }
        },
        error:function(err){
            colseMessageToastr();
            if (err.status == 419) {
                messageToastr("error","页面已过期,请刷新网页后重新保存！");
            } else {
                messageToastr("error","网络异常,请联系客服处理！");
            }
        }
    })
}

function usersUnitForm(status,platfrom_detial) {
    if (status == "refresh") {
        messageToastr("load","刷新中,请稍等...");
    }
    $.ajax({
        url: "/admin/unit/form/unit_form_users",
        type: "GET",
        data: {
            "users_id":siteHtml.users_id,
            "platfrom_detial":platfrom_detial,
        },
        success:function(result){
            if (result.status == "success") {
                var unitForms = "";
                if (result.data.unitForms.length > 0) {
                    $.each(result.data.unitForms,function(index,unitForm){
                        unitForms += '<option value="'+unitForm.form_id+'">'+unitForm.name+'</option>';
                    });
                } else {
                    unitForms += '<option value="">当前暂无小程序线索表单</option>';
                }
                $("#unit_form_select").html(unitForms);
                if($("#form_id_"+htmldomid).length>0){
                    $("#unit_form_select").val($("#form_id_"+htmldomid).val());
                }
                if (status == "refresh") {
                    // 当前状态为空,刷新后有了那么自动加载一个
                    if (!formStatus) {
                        if (result.data.unitForms.length > 0) {
                            unitFormChange();
                        }
                    }
                    messageToastr("success","小程序线索表单刷新成功!");
                } else if (status == "add") {
                    if (result.data.unitForms.length > 0) {
                        unitFormChange();
                    } else {
                        renderFrom({});
                        messageToastr("error","当前暂无表单,请创建表单后选择表单!");
                    }
                }
            } else {
                messageToastr("error",result.msg);
            }
        },
        error:function(err){
            messageToastr("error","网络异常,请联系客服处理！");
        }
    })
}

function usersSiteComment(status) {
    if (status == "refresh") {
        messageToastr("load","刷新中,请稍等...");
    }
    $.ajax({
        url: "/admin/sites/comment/comment_list_users",
        type: "GET",
        data: {
            "users_id":siteHtml.users_id,
        },
        success:function(result){
            if (result.status == "success") {
                var siteComment = "";
                $.each(result.data.comments,function(index,comment){
                    siteComment += '<option value="'+comment.id+'">'+comment.name+'</option>';
                });
                $("#site_comment_select").html(siteComment);
                if (status == "refresh") {
                    // 当前状态为空,刷新后有了那么自动加载一个
                    if (!commentStatus) {
                        if (result.data.comments.length > 0) {
                            unitCommentChange();
                        }
                    }
                    messageToastr("success","评论模版刷新成功!");
                } else if (status == "add") {
                    if (result.data.comments.length > 0) {
                        unitCommentChange();
                    } else {
                        renderComment({"message":'[]'});
                        messageToastr("error","当前暂无评论模版,请创建评论模版后再选择!");
                    }
                }
            } else {
                messageToastr("error",result.msg);
            }
        },
        error:function(err){
            messageToastr("error","网络异常,请联系客服处理！");
        }
    })
}

function miniappUnitQrcodesChange(status) {
    if (status == "wechat") {
        var miniapp_unit_qrcodes = $("#miniapp_unit_qrcodes").val();
    } else {
        var miniapp_unit_qrcodes = $("#form_unit_qrcode").val();
    }
    $("#form_unit_qrcode").val(miniapp_unit_qrcodes);
    $("#miniapp_unit_qrcodes").val(miniapp_unit_qrcodes);
    siteHtml.qrcodes_lists_id = miniapp_unit_qrcodes;
}

function unitHkzsChange() {
    var kfid = $("#unit_hkzs").val();
    siteHtml.kfid = kfid;
}

function unitFormChange() {
    var form_id = $("#unit_form_select").val();
    var unit_form = JSON.parse(siteHtml.unit_form);
    if (unit_form.indexOf(form_id) < 0) {
        unit_form.push(form_id);
        siteHtml.unit_form = JSON.stringify(unit_form);
    }
    $.ajax({
        url: "/admin/form/unit_form_detial",
        type: "GET",
        data: {
            "users_id":siteHtml.users_id,
            "form_id":form_id,
        },
        success:function(result){
            if (result.status == "success") {
                renderFrom(result.data.unitformSetting);
            } else {
                messageToastr("error",result.msg);
            }
        },
        error:function(err){
            messageToastr("error","网络异常,请联系客服处理！");
        }
    })
}

function unitCommentChange() {
    var comment_id = $("#site_comment_select").val();
    $.ajax({
        url: "/admin/sites/comment/comment_detial",
        type: "GET",
        data: {
            "users_id":siteHtml.users_id,
            "comment_id":comment_id,
        },
        success:function(result){
            if (result.status == "success") {
                renderComment(result.data.comment);
            } else {
                messageToastr("error",result.msg);
            }
        },
        error:function(err){
            messageToastr("error","网络异常,请联系客服处理！");
        }
    })
}

function siteListsPreview(version,date) {
    if (version == "close") {
        $('#previewModal').modal('toggle');
    } else {
        $("#preview_qrcode").hide().html("");
        var site_url = "https://kf.pdb2.com/kf/"+siteHtml.kfid+"?debug_time="+siteHtml.debug_time+"&debug_sign="+siteHtml.debug_sign;
        var qrcode = new QRCode(document.getElementById("preview_qrcode"), {
            text: site_url,
            width: 150,
            height: 150,
            colorDark : "#000000",
            colorLight : "#ffffff",
            correctLevel : QRCode.CorrectLevel.H
        });
        $("#preview_qrcode").show();
        $("#admin_service_text").text("扫码预览落地页");
        $("#admin_service_describe").html("修改落地页后必须发布后才生效；<font style='color:#FD6666'>预览二维码有效期1小时</font>，不能用于推广！");
        $('#previewModal').modal('toggle')
    }
}

function spectrumSetInputColor(id,color) {
    $("#"+id).spectrum({
        color: color,
        cancelText: "取消",
        chooseText: "确定选择",
    });
}